import { FlightInfo } from "./flightApi";
import request from "./request"

export interface TicketInfo {
    /*飞机票ID */
    id: number;

    /*用户名 */
    userLoginId: string;

    /* */
    flightInfo: FlightInfo
}

/**
 * 买票接口
 * @param flightId 航班ID
 * @returns 
 */
export const buyTicketApi = (flightId : number) => {
    return request({
        url: "/ticket/user/",
        method: "PUT",
        params: {
            flightId
        }
    })
}

/**
 * 退票接口
 * @param flightId 航班ID
 * @returns 
 */
export const refundTicketApi = (flightId : number) => {
    return request({
        url: "/ticket/user/",
        method: "DELETE",
        params: {
            flightId
        }
    })
}

/**
 * 获取用户飞机票信息
 * @returns 
 */
export const getTicketInfoApi = () => {
    return request({
        url: "/ticket/user/",
        method: "GET"
    })
}

/**
 * 检查航班是否售罄
 * @param flightId 航班ID
 * @returns 是否售罄
 */
export const isSoldOut = (flightId : number) => {
    return request({
        url: "/ticket/user/soldOut",
        method: "GET",
        params: {
            flightId
        }
    })
}